import { useQueries } from 'react-query';
import { request } from '@/request';

const useInitData = () => {
    const [user, categories, noticeStatus] = useQueries([
        { queryKey: 'user', queryFn: async () => request('/user') },
        { queryKey: 'categories', queryFn: async () => request('/categories') },
        { queryKey: 'notices/isnew', queryFn: async () => request('notices/isnew'), staleTime: 10 * 1000 },
    ])

    return {
        user: user?.data?.data ?? { mainGroup: '' },
        refetchUser: user?.refetch,
        refetchNoticeStatus:noticeStatus?.refetch,
        categories: categories?.data?.data?.list,
        isNoticeNew: noticeStatus?.data?.data?.isNew,
        isLoading: user.isLoading || categories.isLoading || noticeStatus.isLoading
    }
}

export default useInitData